package PLCSymbolAndScope.PLCSymbols;

import PLCSymbolAndScope.IDGenerator;
import PLCSymbolAndScope.PLCScope.PLCScope;
import PLCSymbolAndScope.PLCScopeStack;
import PLCSymbolAndScope.PLCSymbolTables.PLCSymbolTable;

//需要设置符号ID、类型ID、所属作用域引用、所属符号表引用、符号名、列数行数

public class PLCSymbol {
    //每个符号唯一的ID 在构造方法中自动生成
    private int symbolId;

    //符号的类型标识符，内置类型的类型标识符是内置的，自定义类型的标识符由程序给出
    private int typeId;

    //符号名称
    public String name;

    //符号所在行数
    public int rowNum;

    //符号所在列数
    public int columnNum;

    //符号所属作用域, 在初始化时自动设置，默认为栈顶作用域，也可以手动设置
    public PLCScope localScope;

    //指向所属符号表,默认为栈顶作用域符号表
    public PLCSymbolTable localSymbolTable;

    //具体参数构造方法
    public PLCSymbol(int typeId, String name, int rowNum){
        this.typeId = typeId;
        this.name = name;
        this.rowNum = rowNum;
        this.localSymbolTable = PLCScopeStack.currentSymbolTable;
        this.localScope = PLCScopeStack.currentScope;
        this.symbolId = IDGenerator.newSymbolId();
    }

    //默认构造方法，需要另外设置typeId name rowNum
    public PLCSymbol(){
        this.localSymbolTable = PLCScopeStack.currentSymbolTable;
        this.localScope = PLCScopeStack.currentScope;
        this.symbolId = IDGenerator.newSymbolId();
    }

    public PLCSymbol(String name){
        this.localSymbolTable = PLCScopeStack.currentSymbolTable;
        this.localScope = PLCScopeStack.currentScope;
        this.symbolId = IDGenerator.newSymbolId();
        this.name = name;
    }

    //用于创建临时符号信息载体使用
    public PLCSymbol(int defaultNum){
        //null
    }

    //根据符号表或作用域设置所属
    public void setLocal(PLCScope localScope){
        this.localSymbolTable = localScope.getScopeSymbolTable();
        this.localScope = localScope;
    }
    public void setLocal(PLCSymbolTable localTable){
        this.localSymbolTable = localTable;
        this.localScope = localTable.getTableScope();
    }

    public void setTypeId(int typeId){

        this.typeId = typeId;

    }

    public int getTypeId(){
        return this.typeId;
    }

    public int getSymbolId() {
        return symbolId;
    }

    public void setSymbolId(int symbolId){
        this.symbolId = symbolId;
    }

    public void setName(String name){
        this.name = name;
    }

    public String getName() {
        return this.name;
    }


    /*
    public void toString(){

    }
    */
}
